/**
 *
 */
import Util;
import OSS;
import OpenPlatform;
import OSSUtil;
import FileForm;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  
  checkConfig(config);
  @endpoint = getEndpoint('imagerecog', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model ClassifyingRubbishRequest {
  imageURL?: string(name='ImageURL', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/ClassifyingRubbish/ClassifyingRubbish6.jpg'),
}

model ClassifyingRubbishAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/ClassifyingRubbish/ClassifyingRubbish6.jpg'),
}

model ClassifyingRubbishResponseBody = {
  data?: {
    elements?: [ 
      {
        category?: string(name='Category'),
        categoryScore?: float(name='CategoryScore', example='0.9406'),
        rubbish?: string(name='Rubbish'),
        rubbishScore?: float(name='RubbishScore', example='0.9406'),
      }
    ](name='Elements'),
    sensitive?: boolean(name='Sensitive', example='false'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='1619647E-92ED-5641-A1D9-F05C33FD294A'),
}

model ClassifyingRubbishResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ClassifyingRubbishResponseBody(name='body'),
}

async function classifyingRubbishWithOptions(request: ClassifyingRubbishRequest, runtime: Util.RuntimeOptions): ClassifyingRubbishResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.imageURL)) {
    body['ImageURL'] = request.imageURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ClassifyingRubbish',
    version = '2019-09-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function classifyingRubbish(request: ClassifyingRubbishRequest): ClassifyingRubbishResponse {
  var runtime = new Util.RuntimeOptions{};
  return classifyingRubbishWithOptions(request, runtime);
}

async function classifyingRubbishAdvance(request: ClassifyingRubbishAdvanceRequest, runtime: Util.RuntimeOptions): ClassifyingRubbishResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imagerecog',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var classifyingRubbishReq = new ClassifyingRubbishRequest{};
  OpenApiUtil.convert(request, classifyingRubbishReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    classifyingRubbishReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var classifyingRubbishResp = classifyingRubbishWithOptions(classifyingRubbishReq, runtime);
  return classifyingRubbishResp;
}

model DetectFruitsRequest {
  imageURL?: string(name='ImageURL', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/DetectFruits/DetectFruits1.jpg'),
}

model DetectFruitsAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/DetectFruits/DetectFruits1.jpg'),
}

model DetectFruitsResponseBody = {
  data?: {
    elements?: [ 
      {
        box?: [ float ](name='Box'),
        name?: string(name='Name'),
        score?: float(name='Score', example='0.7757113575935364'),
      }
    ](name='Elements'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='AFD9185D-4966-476C-8BED-5DABB7A0AFB5'),
}

model DetectFruitsResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: DetectFruitsResponseBody(name='body'),
}

async function detectFruitsWithOptions(request: DetectFruitsRequest, runtime: Util.RuntimeOptions): DetectFruitsResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.imageURL)) {
    body['ImageURL'] = request.imageURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'DetectFruits',
    version = '2019-09-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function detectFruits(request: DetectFruitsRequest): DetectFruitsResponse {
  var runtime = new Util.RuntimeOptions{};
  return detectFruitsWithOptions(request, runtime);
}

async function detectFruitsAdvance(request: DetectFruitsAdvanceRequest, runtime: Util.RuntimeOptions): DetectFruitsResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imagerecog',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var detectFruitsReq = new DetectFruitsRequest{};
  OpenApiUtil.convert(request, detectFruitsReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    detectFruitsReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var detectFruitsResp = detectFruitsWithOptions(detectFruitsReq, runtime);
  return detectFruitsResp;
}

model DetectImageElementsRequest {
  url?: string(name='Url', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/DetectImageElements/DetectImageElements5.jpg'),
}

model DetectImageElementsAdvanceRequest {
  urlObject?: readable(name='Url', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/DetectImageElements/DetectImageElements5.jpg'),
}

model DetectImageElementsResponseBody = {
  data?: {
    elements?: [ 
      {
        height?: int32(name='Height', example='354'),
        score?: float(name='Score', example='0.997097373008728'),
        type?: string(name='Type', example='majorhuman'),
        width?: int32(name='Width', example='285'),
        x?: int32(name='X', example='287'),
        y?: int32(name='Y', example='78'),
      }
    ](name='Elements'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='7EE82437-AEC4-5AAF-819F-AB28C23EE0FC'),
}

model DetectImageElementsResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: DetectImageElementsResponseBody(name='body'),
}

async function detectImageElementsWithOptions(request: DetectImageElementsRequest, runtime: Util.RuntimeOptions): DetectImageElementsResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.url)) {
    body['Url'] = request.url;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'DetectImageElements',
    version = '2019-09-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function detectImageElements(request: DetectImageElementsRequest): DetectImageElementsResponse {
  var runtime = new Util.RuntimeOptions{};
  return detectImageElementsWithOptions(request, runtime);
}

async function detectImageElementsAdvance(request: DetectImageElementsAdvanceRequest, runtime: Util.RuntimeOptions): DetectImageElementsResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imagerecog',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var detectImageElementsReq = new DetectImageElementsRequest{};
  OpenApiUtil.convert(request, detectImageElementsReq);

  if(!Util.isUnset(request.urlObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.urlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    detectImageElementsReq.url = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var detectImageElementsResp = detectImageElementsWithOptions(detectImageElementsReq, runtime);
  return detectImageElementsResp;
}

model EvaluateCertificateQualityRequest {
  imageURL?: string(name='ImageURL', example='https://viapi-doc.oss-cn-shanghai.aliyuncs.com/imagerecog/xxxxx.jpg'),
  type?: string(name='Type', example='BusinessLicense'),
}

model EvaluateCertificateQualityAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', example='https://viapi-doc.oss-cn-shanghai.aliyuncs.com/imagerecog/xxxxx.jpg'),
  type?: string(name='Type', example='BusinessLicense'),
}

model EvaluateCertificateQualityResponseBody = {
  data?: {
    elements?: [ 
      {
        pass?: string(name='Pass', example='false'),
        score?: string(name='Score', example='0.06514739990234375'),
        value?: string(name='Value', example='lackoffront'),
      }
    ](name='Elements'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='656318DC-3856-43E3-9147-859532721AD6'),
}

model EvaluateCertificateQualityResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: EvaluateCertificateQualityResponseBody(name='body'),
}

async function evaluateCertificateQualityWithOptions(request: EvaluateCertificateQualityRequest, runtime: Util.RuntimeOptions): EvaluateCertificateQualityResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.imageURL)) {
    body['ImageURL'] = request.imageURL;
  }
  if (!Util.isUnset(request.type)) {
    body['Type'] = request.type;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'EvaluateCertificateQuality',
    version = '2019-09-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function evaluateCertificateQuality(request: EvaluateCertificateQualityRequest): EvaluateCertificateQualityResponse {
  var runtime = new Util.RuntimeOptions{};
  return evaluateCertificateQualityWithOptions(request, runtime);
}

async function evaluateCertificateQualityAdvance(request: EvaluateCertificateQualityAdvanceRequest, runtime: Util.RuntimeOptions): EvaluateCertificateQualityResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imagerecog',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var evaluateCertificateQualityReq = new EvaluateCertificateQualityRequest{};
  OpenApiUtil.convert(request, evaluateCertificateQualityReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    evaluateCertificateQualityReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var evaluateCertificateQualityResp = evaluateCertificateQualityWithOptions(evaluateCertificateQualityReq, runtime);
  return evaluateCertificateQualityResp;
}

model GetAsyncJobResultRequest {
  jobId?: string(name='JobId', example='72CFDC08-3FEF-56AA-91E5-B14DE31C09C2'),
}

model GetAsyncJobResultResponseBody = {
  data?: {
    errorCode?: string(name='ErrorCode', example='InvalidParameter'),
    errorMessage?: string(name='ErrorMessage', example='paramsIllegal'),
    jobId?: string(name='JobId', example='72CFDC08-3FEF-56AA-91E5-B14DE31C09C2'),
    result?: string(name='Result', example='{\\"tags\\":[{\\"confidence\\":-1,\\"value\\":\\"{\\\\\\"tagInfo\\\\\\": {\\\\\\"humanInfo\\\\\\": [[{\\\\\\"category\\\\\\": \\\\\\"human-real-normal\\\\\\", \\\\\\"score\\\\\\": 0.9690580798778683, \\\\\\"bbox\\\\\\": [77, 280, 431, 569], \\\\\\"cloth_category\\\\\\": \\\\\\"modern\\\\\\", \\\\\\"cloth_category_score\\\\\\": 0.7393399477005005}]], \\\\\\"sceneInfo\\\\\\": [[{\\\\\\"category\\\\\\": \\\\\\"gamescreen-gameeffect\\\\\\", \\\\\\"score\\\\\\": 0.44200169294841274}]], \\\\\\"objectInfo\\\\\\": [null]}}\\"}]}'),
    status?: string(name='Status', example='PROCESS_SUCCESS'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='572974F0-1014-5C60-97EE-DBFFC0FF7616'),
}

model GetAsyncJobResultResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetAsyncJobResultResponseBody(name='body'),
}

async function getAsyncJobResultWithOptions(request: GetAsyncJobResultRequest, runtime: Util.RuntimeOptions): GetAsyncJobResultResponse {
  Util.validateModel(request);
  var query = OpenApiUtil.query(Util.toMap(request));
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetAsyncJobResult',
    version = '2019-09-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'GET',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getAsyncJobResult(request: GetAsyncJobResultRequest): GetAsyncJobResultResponse {
  var runtime = new Util.RuntimeOptions{};
  return getAsyncJobResultWithOptions(request, runtime);
}

model RecognizeFoodRequest {
  imageURL?: string(name='ImageURL', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/RecognizeFood/RecognizeFood5.jpg'),
}

model RecognizeFoodAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/RecognizeFood/RecognizeFood5.jpg'),
}

model RecognizeFoodResponseBody = {
  data?: {
    topFives?: [ 
      {
        calorie?: string(name='Calorie', example='208'),
        category?: string(name='Category'),
        score?: float(name='Score', example='0.2083740234375'),
      }
    ](name='TopFives'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='4C2369C5-54E0-4B9F-8ACB-80C4F50AD2DB'),
}

model RecognizeFoodResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: RecognizeFoodResponseBody(name='body'),
}

async function recognizeFoodWithOptions(request: RecognizeFoodRequest, runtime: Util.RuntimeOptions): RecognizeFoodResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.imageURL)) {
    body['ImageURL'] = request.imageURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'RecognizeFood',
    version = '2019-09-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function recognizeFood(request: RecognizeFoodRequest): RecognizeFoodResponse {
  var runtime = new Util.RuntimeOptions{};
  return recognizeFoodWithOptions(request, runtime);
}

async function recognizeFoodAdvance(request: RecognizeFoodAdvanceRequest, runtime: Util.RuntimeOptions): RecognizeFoodResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imagerecog',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var recognizeFoodReq = new RecognizeFoodRequest{};
  OpenApiUtil.convert(request, recognizeFoodReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    recognizeFoodReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var recognizeFoodResp = recognizeFoodWithOptions(recognizeFoodReq, runtime);
  return recognizeFoodResp;
}

model RecognizeImageColorRequest {
  colorCount?: int32(name='ColorCount', example='5'),
  url?: string(name='Url', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/RecognizeImageColor/RecognizeImageColor1.jpg'),
}

model RecognizeImageColorAdvanceRequest {
  colorCount?: int32(name='ColorCount', example='5'),
  urlObject?: readable(name='Url', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/RecognizeImageColor/RecognizeImageColor1.jpg'),
}

model RecognizeImageColorResponseBody = {
  data?: {
    colorTemplateList?: [ 
      {
        color?: string(name='Color', example='270315'),
        label?: string(name='Label', example='red'),
        percentage?: float(name='Percentage', example='0.459527'),
      }
    ](name='ColorTemplateList'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='CCC7C1D9-8C0F-58AD-ADE3-C331B83BD6F2'),
}

model RecognizeImageColorResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: RecognizeImageColorResponseBody(name='body'),
}

async function recognizeImageColorWithOptions(request: RecognizeImageColorRequest, runtime: Util.RuntimeOptions): RecognizeImageColorResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.colorCount)) {
    body['ColorCount'] = request.colorCount;
  }
  if (!Util.isUnset(request.url)) {
    body['Url'] = request.url;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'RecognizeImageColor',
    version = '2019-09-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function recognizeImageColor(request: RecognizeImageColorRequest): RecognizeImageColorResponse {
  var runtime = new Util.RuntimeOptions{};
  return recognizeImageColorWithOptions(request, runtime);
}

async function recognizeImageColorAdvance(request: RecognizeImageColorAdvanceRequest, runtime: Util.RuntimeOptions): RecognizeImageColorResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imagerecog',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var recognizeImageColorReq = new RecognizeImageColorRequest{};
  OpenApiUtil.convert(request, recognizeImageColorReq);

  if(!Util.isUnset(request.urlObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.urlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    recognizeImageColorReq.url = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var recognizeImageColorResp = recognizeImageColorWithOptions(recognizeImageColorReq, runtime);
  return recognizeImageColorResp;
}

model RecognizeImageStyleRequest {
  url?: string(name='Url', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/RecognizeImageStyle/RecognizeImageStyle1.jpg'),
}

model RecognizeImageStyleAdvanceRequest {
  urlObject?: readable(name='Url', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/RecognizeImageStyle/RecognizeImageStyle1.jpg'),
}

model RecognizeImageStyleResponseBody = {
  data?: {
    styles?: [ string ](name='Styles'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='66FC3009-9A7A-4D29-8B70-D6EB256EF590'),
}

model RecognizeImageStyleResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: RecognizeImageStyleResponseBody(name='body'),
}

async function recognizeImageStyleWithOptions(request: RecognizeImageStyleRequest, runtime: Util.RuntimeOptions): RecognizeImageStyleResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.url)) {
    body['Url'] = request.url;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'RecognizeImageStyle',
    version = '2019-09-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function recognizeImageStyle(request: RecognizeImageStyleRequest): RecognizeImageStyleResponse {
  var runtime = new Util.RuntimeOptions{};
  return recognizeImageStyleWithOptions(request, runtime);
}

async function recognizeImageStyleAdvance(request: RecognizeImageStyleAdvanceRequest, runtime: Util.RuntimeOptions): RecognizeImageStyleResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imagerecog',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var recognizeImageStyleReq = new RecognizeImageStyleRequest{};
  OpenApiUtil.convert(request, recognizeImageStyleReq);

  if(!Util.isUnset(request.urlObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.urlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    recognizeImageStyleReq.url = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var recognizeImageStyleResp = recognizeImageStyleWithOptions(recognizeImageStyleReq, runtime);
  return recognizeImageStyleResp;
}

model RecognizeSceneRequest {
  imageURL?: string(name='ImageURL', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/RecognizeScene/RecognizeScene1.jpg'),
}

model RecognizeSceneAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/RecognizeScene/RecognizeScene1.jpg'),
}

model RecognizeSceneResponseBody = {
  data?: {
    tags?: [ 
      {
        confidence?: float(name='Confidence', example='79'),
        value?: string(name='Value'),
      }
    ](name='Tags'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='AC79F887-5CCB-42BE-8AC3-4D455EFEDB94'),
}

model RecognizeSceneResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: RecognizeSceneResponseBody(name='body'),
}

async function recognizeSceneWithOptions(request: RecognizeSceneRequest, runtime: Util.RuntimeOptions): RecognizeSceneResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.imageURL)) {
    body['ImageURL'] = request.imageURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'RecognizeScene',
    version = '2019-09-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function recognizeScene(request: RecognizeSceneRequest): RecognizeSceneResponse {
  var runtime = new Util.RuntimeOptions{};
  return recognizeSceneWithOptions(request, runtime);
}

async function recognizeSceneAdvance(request: RecognizeSceneAdvanceRequest, runtime: Util.RuntimeOptions): RecognizeSceneResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imagerecog',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var recognizeSceneReq = new RecognizeSceneRequest{};
  OpenApiUtil.convert(request, recognizeSceneReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    recognizeSceneReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var recognizeSceneResp = recognizeSceneWithOptions(recognizeSceneReq, runtime);
  return recognizeSceneResp;
}

model RecognizeVehicleTypeRequest {
  imageURL?: string(name='ImageURL', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/RecognizeVehicleType/RecognizeVehicleType5.jpg'),
}

model RecognizeVehicleTypeAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/RecognizeVehicleType/RecognizeVehicleType5.jpg'),
}

model RecognizeVehicleTypeResponseBody = {
  data?: {
    elements?: [ 
      {
        name?: string(name='Name', example='car'),
        score?: float(name='Score', example='0.9952'),
      }
    ](name='Elements'),
    threshold?: float(name='Threshold', example='0.9952'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='DC2DD4F6-524F-461E-99E0-79A51A6C457B'),
}

model RecognizeVehicleTypeResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: RecognizeVehicleTypeResponseBody(name='body'),
}

async function recognizeVehicleTypeWithOptions(request: RecognizeVehicleTypeRequest, runtime: Util.RuntimeOptions): RecognizeVehicleTypeResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.imageURL)) {
    body['ImageURL'] = request.imageURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'RecognizeVehicleType',
    version = '2019-09-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function recognizeVehicleType(request: RecognizeVehicleTypeRequest): RecognizeVehicleTypeResponse {
  var runtime = new Util.RuntimeOptions{};
  return recognizeVehicleTypeWithOptions(request, runtime);
}

async function recognizeVehicleTypeAdvance(request: RecognizeVehicleTypeAdvanceRequest, runtime: Util.RuntimeOptions): RecognizeVehicleTypeResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imagerecog',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var recognizeVehicleTypeReq = new RecognizeVehicleTypeRequest{};
  OpenApiUtil.convert(request, recognizeVehicleTypeReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    recognizeVehicleTypeReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var recognizeVehicleTypeResp = recognizeVehicleTypeWithOptions(recognizeVehicleTypeReq, runtime);
  return recognizeVehicleTypeResp;
}

model TaggingAdImageRequest {
  imageURL?: string(name='ImageURL', example='https://viapi-demo.oss-cn-shanghai.aliyuncs.com/viapi-demo/images/DetectImageElements/xxxx.png'),
}

model TaggingAdImageAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', example='https://viapi-demo.oss-cn-shanghai.aliyuncs.com/viapi-demo/images/DetectImageElements/xxxx.png'),
}

model TaggingAdImageResponseBody = {
  data?: {
    tagInfo?: map[string]any(name='TagInfo'),
  }(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId', example='572974F0-1014-5C60-97EE-DBFFC0FF7616'),
}

model TaggingAdImageResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: TaggingAdImageResponseBody(name='body'),
}

async function taggingAdImageWithOptions(request: TaggingAdImageRequest, runtime: Util.RuntimeOptions): TaggingAdImageResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.imageURL)) {
    body['ImageURL'] = request.imageURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'TaggingAdImage',
    version = '2019-09-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function taggingAdImage(request: TaggingAdImageRequest): TaggingAdImageResponse {
  var runtime = new Util.RuntimeOptions{};
  return taggingAdImageWithOptions(request, runtime);
}

async function taggingAdImageAdvance(request: TaggingAdImageAdvanceRequest, runtime: Util.RuntimeOptions): TaggingAdImageResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imagerecog',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var taggingAdImageReq = new TaggingAdImageRequest{};
  OpenApiUtil.convert(request, taggingAdImageReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    taggingAdImageReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var taggingAdImageResp = taggingAdImageWithOptions(taggingAdImageReq, runtime);
  return taggingAdImageResp;
}

model TaggingImageRequest {
  imageURL?: string(name='ImageURL', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/TaggingImage/TaggingImage1.jpg'),
}

model TaggingImageAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/TaggingImage/TaggingImage1.jpg'),
}

model TaggingImageResponseBody = {
  data?: {
    tags?: [ 
      {
        confidence?: float(name='Confidence', example='65'),
        value?: string(name='Value'),
      }
    ](name='Tags'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='70ED13B0-BC22-576D-9CCF-1CC12FEAC477'),
}

model TaggingImageResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: TaggingImageResponseBody(name='body'),
}

async function taggingImageWithOptions(request: TaggingImageRequest, runtime: Util.RuntimeOptions): TaggingImageResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.imageURL)) {
    body['ImageURL'] = request.imageURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'TaggingImage',
    version = '2019-09-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function taggingImage(request: TaggingImageRequest): TaggingImageResponse {
  var runtime = new Util.RuntimeOptions{};
  return taggingImageWithOptions(request, runtime);
}

async function taggingImageAdvance(request: TaggingImageAdvanceRequest, runtime: Util.RuntimeOptions): TaggingImageResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imagerecog',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var taggingImageReq = new TaggingImageRequest{};
  OpenApiUtil.convert(request, taggingImageReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    taggingImageReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var taggingImageResp = taggingImageWithOptions(taggingImageReq, runtime);
  return taggingImageResp;
}

